package view;

import controller.MaquinaTuringController;
import javax.swing.JOptionPane;

/**
 * @author lucasamaral
 * @author fernando
 */
public class MaquinaTuringView extends javax.swing.JFrame {

  private MaquinaTuringController controller = new MaquinaTuringController();

  /**
   * Método Construtor da Classe.
   */
  public MaquinaTuringView() {
    initComponents();
    jButtonIniciar.setVisible(false);
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jButtonIniciar = new javax.swing.JButton();
    jButtonArquivo = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextAreaResultado = new javax.swing.JTextArea();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jButtonIniciar.setText("Processar MT");
    jButtonIniciar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonIniciarActionPerformed(evt);
      }
    });

    jButtonArquivo.setText("Selecionar Arquivo");
    jButtonArquivo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonArquivoActionPerformed(evt);
      }
    });

    jTextAreaResultado.setColumns(20);
    jTextAreaResultado.setRows(5);
    jScrollPane1.setViewportView(jTextAreaResultado);

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
        .addContainerGap()
        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
          .add(layout.createSequentialGroup()
            .add(jButtonArquivo)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 86, Short.MAX_VALUE)
            .add(jButtonIniciar)
            .addContainerGap())
          .add(layout.createSequentialGroup()
            .add(jScrollPane1)
            .add(14, 14, 14))))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
          .add(jButtonArquivo)
          .add(jButtonIniciar))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButtonIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIniciarActionPerformed
      if (controller.getArquivo().getArquivoEntrada() != null) {
        controller.testaMaquina(jTextAreaResultado);
        JOptionPane.showMessageDialog(this, "Verificação realizada, arquivo com os resultados gerado.");
      } else {
        JOptionPane.showMessageDialog(this, "Você ainda não selecionou nenhum arquivo de entrada.\nPor favor o faça!");
      }
    }//GEN-LAST:event_jButtonIniciarActionPerformed

  private void jButtonArquivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonArquivoActionPerformed
    controller.getArquivo().carregaArquivoEntrada(this);
    controller.getArquivo().populaEntradas(controller.getMaquinaTuring(), controller.getTransições());
    jButtonIniciar.setVisible(true);
  }//GEN-LAST:event_jButtonArquivoActionPerformed

  /**
   * Método estático responsável pela instância do Objeto View.
   * @param args String de Argumentos.
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {
      new MaquinaTuringView().setVisible(true);
    }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButtonArquivo;
  private javax.swing.JButton jButtonIniciar;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTextArea jTextAreaResultado;
  // End of variables declaration//GEN-END:variables
}
